package com.wzdigit.wms.raw.controller.skutype;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.raw.constant.RawWareConstant;
import com.wzdigit.wms.raw.domain.dto.SkuTypeDto;
import com.wzdigit.wms.raw.domain.skutype.SkuType;
import com.wzdigit.wms.raw.service.skutype.SkuTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@Api(tags = "物料分类")
@RequestMapping(value = RawWareConstant.API_VERSION)
public class SkuTypeController {
    public static final String REQUEST_MODEL = "/skuType";

    @Autowired
    SkuTypeService skuTypeService;

    @ApiOperation(value = "主档查询", notes = "主档查询")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUEST_MODEL + "/pageList")
    public PagerInfo<List<SkuType>> selectHoldHeaderList(
            SkuTypeDto search, Pager<?> pager,
            HttpServletResponse servletResponse) {
        try {
            return skuTypeService.pageList(search, pager);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

}
